package com.asia5b.a5mall.middleware.core

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.asia5b.a5mall.middleware.utils.dddLog

/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   Activity生命周期回调
 */
class ActivityLifeController : Application.ActivityLifecycleCallbacks {

    /**
     * @Name  autoClearHelper
     * @Type  com.asia5b.a5mall.middleware.utils.AutoClearHelper
     * @Note  变量清理辅助类
     */
    private var isOpenAutoClear = false

    /**
     * @Note   开启
     */
    fun withAutoValueHelper(): ActivityLifeController {
        isOpenAutoClear = true
        return this
    }

    /**
     * @Note   Activity处于不显示或者半透明状态
     * @return Activity
     */
    override fun onActivityPaused(p0: Activity) {

    }

    /**
     * @Note   Activity处于完全显示状态
     * @return Activity
     */
    override fun onActivityResumed(p0: Activity) {

    }

    override fun onActivityStarted(p0: Activity) {

    }

    /**
     * @Note   Activity销毁方法
     * @return 销毁的Activity
     */
    override fun onActivityDestroyed(p0: Activity) {
        dddLog("PageCreate,页面销毁======>${p0?.javaClass?.simpleName}")
        if (p0 != null) {
            com.asia5b.a5mall.middleware.core.ActivityTask.instance.popFromActivityStack(p0)
        }
    }

    override fun onActivitySaveInstanceState(p0: Activity, p1: Bundle) {

    }

    override fun onActivityStopped(p0: Activity) {

    }

    /**
     * @Note   Activity创建回调
     * @param  p0 创建的Activity
     */
    override fun onActivityCreated(p0: Activity, p1: Bundle?) {
        dddLog("PageCreate,页面创建======>${p0?.javaClass?.simpleName}")
        if (p0 != null) {
            com.asia5b.a5mall.middleware.core.ActivityTask.instance.pushToActivityStack(p0)
        }
    }
}